<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="jquery-3.6.0.min.js"></script>
  <style>
    * {
      padding: 0;
      margin: 0;
      list-style: none;
    }
    ul {
      height: 50px;
      position: relative;
    }
    li {
      float: left;
      width: 100px;
      height: 50px;
      text-align: center;
      line-height: 50px;
      cursor: pointer;
      font-weight: 500px;
    }
    span {
      position: absolute;
      left: 0;
      top: 50px;
      border: 2px solid #3FA1BF;
      width: 95px;
    }
  </style>
</head>
<body>
  <ul>
    <li>首页</li>
    <li>产品</li>
    <li>新闻</li>
    <li>关于我们</li>
    <li>联系我们</li>
    <span></span>
  </ul>
  <script>
      var num = $('li').outerWidth();
      $('li').mouseover(function () {
        var index = $(this).index();
        $('span').stop().animate({
          left: num * index,
        }, 300);
      });
  </script>
</body>
</html>